﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NuMvvm.Validation
{
    public sealed class NotEmptyAttribute : ValidationAttribute
    {
        public NotEmptyAttribute()
            : base("The field \"{0}\" cannot be empty.")
        {
         
        }

        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            ValidationResult result = null;
            if(value == null || string.IsNullOrWhiteSpace(value.ToString()))
            {
                result = new ValidationResult(ErrorMessage);
            }
            return result;
        }
    }
}
